using System;
using System.Collections.Generic;
using System.Linq;
using ApiProject.Api.Data;
using ApiProject.Api.Entity;
using ApiProject.Api.PramaModel;
using ApiProject.Api.Repository;
using ApiProject.Api.Uitls;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;

//后台用户登录
namespace ApiProject.Api.Controllers
{

    //管理员登录并获取token
    [ApiController]
    [Route("[controller]")]
    public class GscompanyController : ControllerBase
    {
        private IRepository<Articles> _articleRepository;
        private IRepository<ArticleTypes> _articletypeRepository;


        public GscompanyController(

            IRepository<Articles> articleRepository,
            IRepository<ArticleTypes> articletypeRepository

        )
        {
            _articleRepository = articleRepository;
            _articletypeRepository = articletypeRepository;
        }

        //通过文章类型名称获取获取所有文章
        [AllowAnonymous]
        [HttpPut]
        public dynamic GetAllArticle(NewGsconpany model)
        {
            // ArticleTypeName
            var articleTypeName = model.ArticleTypeName;
            var articletype = _articletypeRepository.Table.Where(x => x.ArticleType == articleTypeName).Where(o => o.IsEnable == true && o.IsDelete == false).FirstOrDefault();
            var id = articletype.Id;
            var allArticeById = _articleRepository.Table.Where(x => x.ArticleTypeNum == id).Where(o=>o.IsEnable==true && o.IsDelete==false).ToList();

            return JsonHelper.Serialize(new
            {
                Code = 200,
                Data = allArticeById,
                MissingFieldException = "成功"
            });
        }





    }
}
